package top.sssd.spi.spring.main;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import top.sssd.spring.spi.api.GreetingService;

import java.util.Map;

@ComponentScan(basePackages = {"top.sssd.spi"})
@SpringBootApplication
public class MainApplication {
    public static void main(String[] args) {
        SpringApplication.run(MainApplication.class, args);
    }

    @Bean
    public CommandLineRunner runner(ApplicationContext applicationContext) {
        return args -> {
            Map<String, GreetingService> beans = applicationContext.getBeansOfType(GreetingService.class);
            beans.forEach((name, service) -> {
                System.out.println("bean name:" + name);
                service.sayHello("sssd");
            });
        };
    }


}
